package org.learn.intermediate.com.polyarr_;

public class PloyArray {
    public static void main(String[] args) {
        Person[] people = new Person[5];
        people[0] = new Person("jack" ,18);
        people[1] = new Student("jack" ,18,88);
        people[2] = new Student("smith" ,18,88);
        people[3] = new Teacher("smith" ,45,8800);
        people[4] = new Teacher("acter" ,34,9800);

        //循环遍历数组，调用say
        for (int i = 0; i < people.length; i++) {
            //动态绑定机制，
            System.out.println(people[i].say());
            if(people[i] instanceof Student){
                ((Student)people[i]).study();
            }else if(people[i] instanceof Teacher){
                ((Teacher)people[i]).teach();
            }
        }
        //用到强转和instanceof比较
    }
}
